﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

/// <summary>
/// user 的摘要说明
/// </summary>
public class flight
{
    public int id { get; set; }//id号

    public string fly_name { get; set; }//航班号

    public string type { get; set; }//机型
                     
  
    public DateTime takeoff_time { get; set; }
   
  
    public DateTime land_time { get; set; }
  
    public string start_place { get; set; }
   
    public string end_place { get; set; }
   
    public int economy_tickect { get; set; }//票数
    
    public float price { get; set; }

    public string errorMsg { get; set; }   //用于存放错误消息


    public DataTable getFlight(string takeoff_time ,string start_place, string end_place)
    {


        StringBuilder sqlStr = new StringBuilder("SELECT* FROM[flight]");
        List<string> wheres = new List<string>();
        if (takeoff_time.Length > 0)
        {
            wheres.Add("[takeoff_time] = '" + takeoff_time + "'");
        }

        if (start_place.Length > 0)
        {
            wheres.Add("([start_place] LIKE '%" + start_place + "%')");
        }

        if (end_place.Length > 0)
        {
            wheres.Add("([end_place] LIKE '%" + end_place + "%')");
        }


        //判断用户是否选择了条件
        if (wheres.Count >0)
        {
           
            string wh = string.Join(" and ", wheres);
            sqlStr.Append(" where " + wh);
        }


        //string sqlStr = "SELECT* FROM[flight]  WHERE ";
        //if (takeoff_time.Length > 0)
        //    sqlStr += "[takeoff_time] = '" + takeoff_time +"'" ;

        //System.Diagnostics.Debug.Write(sqlStr);

        //if (start_place.Length > 0)
        //    sqlStr += "AND([start_place] LIKE '%'"+start_place+"'%') ";
        //if (end_place.Length > 0)
        //    sqlStr += "AND([end_place] LIKE '%'" + end_place + "'%')";
        string sql = sqlStr.ToString();
        System.Diagnostics.Debug.Write(sql);
        DB db = new DB();
        return db.GetDataTable(sql);
    }
}